<template>
  <div class="layout-container interface-contain">
    <PageHeader title="接口管理">
      <template #btns>
        <div class="search common-buttons">
          <div class="span1">
            <span>接口名称</span>
          </div>
          <el-input v-model.trim="formtable.interfacename" autocomplete="off" placeholder="请输入"/>
          <el-button type="info" :icon="Search"  @click="onQuery({ pageNo: 1 })">搜索</el-button>
        </div>
      </template>
      <template #search>
      </template>
    </PageHeader>

    <div class="layout-container-table">
      <CommonTable 
      :showSelection=false
        v-loading="loading" 
        v-model:page="page"
        :total="total"
        :data="state.tableData"
        @onQuery="onQuery"
        :header-cell-style="{'text-align':'center'}" 
        :cell-style="{'text-align':'center'}" 
        style="width: 100%">   
        <el-table-column prop="interfaceName" label="接口名称"  />
        <el-table-column prop="interfaceUrl" label="接口地址"  />
        <el-table-column prop="status" label="接口状态" >
          <template #default="scope" >
            <div style="display: flex;justify-content: center;align-items: center;">
              <span v-if="scope.row.status == 1" style="width: 30px;">
                <i class="dotClass" style="background-color: #67C23A"></i>
              </span>
              <span v-if="scope.row.status == 0" style="width: 30px;">
                <i class="dotClass" style="background-color: #F56C6C"></i>
              </span>
              {{statusFormat[scope.row.status]}}
            </div>
          </template>
        </el-table-column>
      </CommonTable>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ElMessage, ElMessageBox } from 'element-plus';
import { onMounted, ref, reactive } from "vue";
import {   getinterfaceSearch } from '@/api/system/interface'
import store from '@/store'
import PageHeader from '@/components/page-header/index.vue';
import CommonTable from '@/components/common-table/index.vue';
import {
  Plus,
  Delete,
  Download,
  Promotion,
  Search,
  Setting
} from '@element-plus/icons-vue';
import { Page } from '@/components/common-table/type';

const state = reactive<any>({
  tableData: [],
});
const page = reactive<Page>({
  current: 1,
  pageSize: 20,
});
const total = ref<number>(0);
const loading = ref(false);
//表单
//状态图标 0 1
const statusFormat= reactive(["关闭","打开"])
const formtable = reactive({
  interfacename: "",
});

onMounted(() => {
  onQuery({ pageNo: 1 });
});

//表单条件搜索
const onQuery = async(val: any) =>{
  let params = {
    pageNo:page.current,
    pageSize:page.pageSize,
    interfaceName:formtable.interfacename?formtable.interfacename:null,
    ...val,
  }
  loading.value = true;
  let result = await getinterfaceSearch(params);
  loading.value = false;
  total.value=result.data.totalRows;
  state.tableData=result.data.rows;
};
</script>
<style  lang="scss" scoped>
@import '@/assets/style/buttons';
.interface-contain {
  .search {
    display: flex;
    :deep() {
      .el-input--small .el-input__wrapper {
        margin-right: 10px;
      }
    }
  }
  .layout-container-table {
    .el-button--small {
      background: transparent;
      color: rgba(24, 81, 237, 1);
    }
  }

  .search .span1{
    display: inline-block;
    width: 80px;
    margin: auto;
    font-size:14px;
    text-align: center;
  }
  .search .el-input{
    width: 200px;
    margin: auto;
  }

  .search .el-button {
    background: rgb(1, 18, 90);
    border: 0;
  }

  .btns .el-button {
    background: rgb(1, 18, 90);
    border: 0;
  }
  :deep() {
    .el-dialog__body {
      padding: 10px 20px;
    }
  }
  .el-form-item .el-select {
  width: 100%;
  }

/* 状态图标 */
.dotClass {
  width:10px;
  height:10px;
  border-radius: 50%;
  display: block;
  margin-left: 10px;
  }
}
</style>